package com.huaiwei.usmManager.modules.usm.controller;


import com.huaiwei.usmManager.common.utils.R;
import com.huaiwei.usmManager.modules.usm.entity.TypeEntity;
import com.huaiwei.usmManager.modules.usm.service.GoodsService;
import com.huaiwei.usmManager.modules.usm.service.TypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/type")
@Api(tags = "分类")
public class TypeController {

    @Autowired
    private TypeService typeService;


    @PostMapping("/update")
    @ApiOperation("添加或者修改类别")
    public R update(@RequestBody TypeEntity typeEntity){
        typeService.saveOrUpdate(typeEntity);
        return R.ok();
    }

    @DeleteMapping("/delete/{typeid}")
    @ApiOperation("删除类别")
    public R delete(@PathVariable("typeid") Integer typeid ){
        typeService.removeById(typeid);
        return R.ok();
    }

    @GetMapping("/list")
    @ApiOperation("分页查询")
    public R list(@RequestParam Map<String,Object> params){
        return R.ok().put("page",typeService.getPage(params));
    }

    @GetMapping("/select/{id}")
    @ApiOperation("根据id选择")
    public R select(@PathVariable("id") Integer id){
        return R.ok().put("list",typeService.getById(id));
    }
}
